package com.second.app.thread.线程基础.day03.synchronizedmethodlockobject;

/**
 * @Author GYZ
 * @Date 2023/11/21
 * <pre>
 *
 * </pre>
 */
public class Test {

    public static void main(String[] args) {

        //案例1
//        class Thread001 extends Thread {
//            private MyObject myObject;
//
//            public Thread001(MyObject myObject) {
//                this.myObject = myObject;
//            }
//
//            @Override
//            public void run() {
//                myObject.methodA();
//            }
//        }
//        class Thread002 extends Thread {
//            private MyObject myObject;
//
//            public Thread002(MyObject myObject) {
//                this.myObject = myObject;
//            }
//
//            @Override
//            public void run() {
//                myObject.methodA();
//            }
//        }
//
//        MyObject myObject = new MyObject();
//        Thread001 thread001 = new Thread001(myObject);
//        thread001.setName("A");
//        thread001.start();
//
//        Thread002 thread002 = new Thread002(myObject);
//        thread002.setName("B");
//
//        thread002.start();
        class Thread001 extends Thread {
            private MyObject myObject;

            public Thread001(MyObject myObject) {
                this.myObject = myObject;
            }

            @Override
            public void run() {
                myObject.methodA();
            }
        }
        class Thread002 extends Thread {
            private MyObject myObject;

            public Thread002(MyObject myObject) {
                this.myObject = myObject;
            }

            @Override
            public void run() {
                myObject.methodB();
            }
        }

        MyObject myObject = new MyObject();
        Thread001 thread001 = new Thread001(myObject);
        thread001.setName("A");
        thread001.start();

        Thread002 thread002 = new Thread002(myObject);
        thread002.setName("B");

        thread002.start();

    }
}
